package com.CISS.service;

import com.CISS.dao.CisuserMapper;
import com.CISS.dao.CisuserinfoMapper;
import com.CISS.dao.CompanyMapper;
import com.CISS.entity.Cisuser;
import com.CISS.entity.Cisuserinfo;
import com.CISS.entity.Company;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestParam;

import javax.jws.soap.SOAPBinding;
import javax.xml.transform.Result;
import java.sql.Date;
import java.util.List;

@Service

public class CisuserService {

    @Autowired
    private CisuserMapper cisum;

    @Autowired
    private CisuserinfoMapper cisuim;

    @Autowired
    private CompanyMapper cm;

    public boolean login(String username, String password, String type){

        try{
            Cisuser target = cisum.loginCheck(username,password,type);

            if(target!=null)
            {
                return true;
            }
            else
            {
                return false;
            }
        }catch(Exception e){

            return false;
        }
    }

    public boolean registM(String CompanyName, String CompanyAddress,
                           String Username, String password,
                           String name, String phone, String email){
        try{
            int ic = cm.newCompany(CompanyName,CompanyAddress);
            int icisu = cisum.newCisuser(Username,password,"manager");

            Cisuser cs = cisum.selectByUserName(Username);
            Company cc = cm.selectByName(CompanyName);

            Date now = new Date(System.currentTimeMillis());

            cisuim.newCisuserinfo(cs.getId(),cc.getId(),name,phone,email,now,"管理员");

            return true;

        }catch(Exception e){
            return false;
        }
    }

    public boolean registE(String Username, String password,
                           String name, String phone,String email,
                           String CompanyName){
        try{
            int icisu = cisum.newCisuser(Username,password,"employee");
            //int ic = cm.selectByPrimaryKey(CompanyId.intValue());


            Cisuser cs = cisum.selectByUserName(Username);
            Company cc = cm.selectByName(CompanyName);

            Date now = new Date(System.currentTimeMillis());

            cisuim.newCisuserinfo(cs.getId(),cc.getId(),name,phone,email,now,"职员");

            return true;

        }catch(Exception e){
            return false;
        }
    }


}
